 <template>
    <views class="terrace_administrators_add">
        <terrace-administrators-base
        :type="type"  
        :roles="roles"
        @submitRole="submitRole">
        </terrace-administrators-base>
    </views>
</template>



<script>
    import TerraceAdministratorsBase from 'components/terrace/terrace_administrators/child_component/child_component/terrace_administrators_base';


export default {
    name: 'TerraceAdministratorsAdd',
    data(){
        return  {
            type:1,          //type类型；0：查看、1：新增、2：编辑
            roles:[]         //简易角色列表
        }
    },
    components:{
        TerraceAdministratorsBase
    },
    mounted(){
        this.$setRouteTitle();
        //新增时，获取简易角色列表
        this.$raxios.post(this.$mapapi.getSimpleRoleList,{}).then(res => {
            if(res.code != 200)    return Promise.reject(res.msg);
            console.log('res', res);
            if(res.data.length == 0)   return Promise.reject('角色列表为空');
            this.roles = res.data;
        }).catch(res => {
            this.$message.error(res);
        });
    },
    methods:{
        submitRole(data){
            this.$raxios.post(this.$mapapi.saveAdminUser,{data}).then(res =>{
                if(res.code != 200)     return  Promise.reject(res.msg);
                this.$message.success(res.msg);
                setTimeout(()=>{
                     this.$blackRoute({ path: '/terrace_administrators',query:{},that:this})                // 返回指定路由-删除标题栏
                },2000);
            }).catch(res => {
                console.log(res);
                this.$message.error(res);
            });

        }
    }
}
</script>

<style :scope="true">
    .terrace_role_add{
        margin: 10px
    }
</style>